$('.select2').select2();
// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

function GetQueryString(name){
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if(r != null) return unescape(r[2]);
  return null;
}

$(document).ready(function() {
    // $("#product").addClass("active");

    getData();
    function getData() {
        var index = GetQueryString('productId');
        $.ajax({
            type:"get",
            url:"http://114.116.72.220:9999/ProductDetailShow",
            async:true,
            data:{
                productId:index
            },
            success:function(data){
                DataView(data[0]);
            }
        });
    }

    function DataView(data){

        $("#new_productName").val(data.product_name);
        $("#new_productNo").val(data.product_no);
        $("#new_productBrand").val(data.product_brand);
        $("#new_productPrice").val(data.product_price);
        $("#new_productType").val(data.product_model).trigger('change');
        $("#new_productClass").val(data.product_status).trigger('change');
        if (data.product_status == '1') {
            $("#group").show();
            $("#new_productGroup1").val(data.product_type[0]).trigger('change');
            $("#new_productGroup2").val(data.product_type[1]).trigger('change');
        }
        if (data.product_status == '2') {
            $("#new_reference_price").val(data.product_refer);
        }

        var img = `<img src="${data.product_thumbnail}" class="img_sty"/>`;
        $('.Thumbnail').html(img);
        img = `<img src="${data.product_detail}" class="img_sty" />`;
        $('.detail_pic').html(img);

        for (var i=0;i<5;i++) {
            var Td = `<img src="${data.product_img[i]}"  class="img_sty" />`;
            $('.product_banner'+(i+1)).html(Td);
        }
    }

    $('#new_productGroup1').change(function () {
        var man = ['套西', '单西', '裤子', '长袖衬衣', '短袖衬衣', '马甲', '大衣', '风衣', '夹克', '中华立领', '中式西服'];
        var woman = ['套西', '单西', '裤子', '长袖衬衣', '短袖衬衣', '短裙', '大衣', '风衣', '连衣裙', '旗袍', '中式西服'];
        var child = ['套西', '单西', '裤子', '长袖衬衣', '短袖衬衣', '短裙', '大衣', '风衣'];
        var work = ['男士西装', '男士衬衣', '男士裤子', '男士大衣', '男士风衣', '女士西装', '女士衬衣', '女士短裙', '女士大衣', '女士风衣', '连衣裙'];
        var group2 = [];
        var group1 = $("#new_productGroup1").val();
        if (group1 == "男装") {
            group2 = man;
        }else if (group1 == "女装") {
            group2 = woman;
        } else if (group1 == "童装") {
            group2 = child;
        } else if (group1 == "职业装") {
            group2 = work;
        }

        $("#new_productGroup2").empty();
        for (var i = 0; i < group2.length; i++) {
            var text = `<option value='${group2[i]}'>${group2[i]}</option>`;
            $("#new_productGroup2").append(text);
        }
    });
});